<?php
namespace Admin\Controller;
//配送时间

use Common\Controller\AdminbaseController;

class DistributionController extends AdminbaseController{

	// 配送时间列表
	public function index(){
        $list = array(
            array('id'=>0,'city_name'=>'长宁区','time'=>'18:00','day'=>'3','distributiontime'=>'08:00-10:00,12:00-14:00'),
            array('id'=>1,'city_name'=>'徐汇区','time'=>'17:00','day'=>'2','distributiontime'=>'09:00-11:00,13:00-15:00'),
        );
        $this->assign('list',$list);
		$this->display();
	}

	// 配送时间添加
	public function add(){
	    $city = array(array('city_id'=>0,'city_name'=>'长宁区'),array('city_id'=>1,'city_name'=>'徐汇区'));
        $this->assign('city',$city);
		$this->display();
	}

	// 配送时间添加提交
	public function add_post(){
		if(IS_POST){
            echo '<pre>';
            print_r($_POST);
            $distributiontime = [];
            for ($i = 0;$i < count($_POST['start_time']);$i++){
                $distributiontime[$i] = $_POST['start_time'][$i]."-".$_POST['end_time'][$i];
            }
            $distributiontime = implode(',',$distributiontime);
            echo $distributiontime;

		}
	}

	// 配送时间编辑
	public function edit(){
	    $id = I('get.id',0,'intval');
        $list = array(
            array('id'=>0,'city_id'=>0,'city_name'=>'长宁区','time'=>'18:00','day'=>'3','distributiontime'=>'08:00-10:00,12:00-14:00,17:00-19:00','use_flg'=>1),
            array('id'=>1,'city_id'=>1,'city_name'=>'徐汇区','time'=>'17:00','day'=>'2','distributiontime'=>'09:00-11:00,13:00-15:00,16:00-17:00','use_flg'=>0),
        );
        $dis = $list[$id];

        $dis['distributiontime'] = explode(',',$dis['distributiontime']);
        $dis['start_time'] = [];
        $dis['end_time'] = [];
        for ($i = 0;$i < count($dis['distributiontime']);$i++){
            $dis['start_time'][$i] = explode('-',$dis['distributiontime'][$i])[0];
            $dis['end_time'][$i] = explode('-',$dis['distributiontime'][$i])[1];
        }
        $dis['count_time'] = count($dis['distributiontime']);
//        echo "<pre>";
//        print_r($dis);die;
        $city = array(array('city_id'=>0,'city_name'=>'长宁区'),array('city_id'=>1,'city_name'=>'徐汇区'));
        $this->assign('city',$city);
		$this->assign('dis',$dis);
		$this->display();
	}

	// 配送时间编辑提交
	public function edit_post(){
		if (IS_POST) {
            echo "<pre>";
            print_r($_POST);
		}
	}

	// 配送时间删除
	public function delete(){
	    $id = I('get.id',0,'intval');
		if ($this->sms_model->delete($id)!==false) {
			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}

}